/*
 * @Description  :
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2022-03-14 14:17:38
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-04-11 21:33:13
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\ticket-management\\components\\etc-invoiced-list\\transaction-details\\transaction-details.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STComponent, STColumn, STChange, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFDateWidgetSchema, SFSchema } from '@delon/form';
import { NzModalService } from 'ng-zorro-antd/modal';
import { TicketService } from '../../../services/ticket.service';

@Component({
  selector: 'app-transaction-details',
  templateUrl: './transaction-details.component.html'
})
export class TransactionDetailsComponent implements OnInit {
  data: any = [];
  selectedData = [];
  url = `/api/fcc/ficoEtcInvoiceH/list/page`;
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  columns: STColumn[] = [
    { title: '交易id', index: 'tradeId' },
    { title: '交易流水号', index: 'tradeFlowNo' },
    {
      title: '交易金额',
      index: 'fee',
      type: 'widget',
      className: 'text-right',
      widget: { type: 'currency-chy', params: ({ record }) => ({ value: record.fee }) }
    },
    { title: '开票状态', index: 'stateLabel' },
    { title: '交易时间', index: 'exTime', type: 'date' }
  ];
  searchSchema: SFSchema = {
    properties: {
      state: {
        type: 'string',
        title: '开票状态',
        enum: [
          { label: '全部', value: '' },
          { label: '待开具', value: '1' },
          { label: '开具中', value: '2' },
          { label: '已开具', value: '3' },
          { label: '交易异常', value: '4' }
        ],
        ui: {
          widget: 'select',
          placeholder: '请选择'
        },
        default: ''
      },
      exTime: {
        title: '交易时间',
        type: 'string',
        ui: {
          widget: 'sl-from-to-search',
          format: 'yyyy-MM-dd'
        } as SFDateWidgetSchema
      }
    }
  };

  constructor(public service: TicketService, private nzModalService: NzModalService, private router: Router) {}

  ngOnInit(): void {
    console.log(this.data);
  }
  get reqParams() {
    const a: any = {};
    if (this.data?.id) {
      a.waybillId = this.data?.wayBillId;
    }
    const params: any = Object.assign({}, this.sf?.value || {});
    delete params._$expand;
    return {
      ...a,
      ...params,
      exTime: {
        start: this.sf?.value?.exTime?.[0] || '',
        end: this.sf?.value?.exTime?.[1] || ''
      }
    };
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
  }
}
